package com.jd.jobkeeper.server.configure;

import com.jd.jobkeeper.utils.net.NetUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ServerConfigure {

    @Value("${r.server.port:18000}")
    private int rPort;


    @Bean
    public ServerConfig serverConfig() {
        ServerConfig serverConfig = new ServerConfig();
        serverConfig.setPort(rPort);
        String host = NetUtils.findFirstNonLoopbackAddress(true, null).getHostAddress();
        serverConfig.setHost(host);
        serverConfig.setId(host + ":" + rPort);

        return serverConfig;
    }

}
